//
//  CurrentGet.m
//  YuTouSeeder
//
//  Created by Huang Dong on 10-9-23.
//  Copyright 2010 limboworks.com. All rights reserved.
//

#import "CurrentGet.h"


@implementation CurrentGet
-(id)init{
	[super init];
	currentItunes = [[NSString alloc]initWithString:@"None"];
	return self;
}

-(void)dealloc{
	[currentItunes release];
	[super dealloc];
}

-(NSString *) CurrentItunes{
	// load the script from a resource by fetching its URL from within our bundle
	NSDictionary *errorDict;
	NSAppleEventDescriptor *returnDescriptor;
    
	NSString *scriptPath = [[NSBundle mainBundle] pathForResource:@"CurrentItunes" ofType:@"scpt"];
	
	NSAppleScript *theScript = [[NSAppleScript alloc] initWithContentsOfURL: [NSURL fileURLWithPath: scriptPath] error: nil];
	returnDescriptor=[theScript executeAndReturnError: &errorDict];
	
	if ([returnDescriptor descriptorType]) {
        //	The execution succeeded
        NSLog(@"script executed sucessfully.");
        if (kAENullEvent!=[returnDescriptor descriptorType]) {
			NSLog(@"script return:%@",[returnDescriptor stringValue]);
			NSString *returnString=[returnDescriptor stringValue];
			if (![currentItunes isEqualToString:returnString]) {
				[currentItunes release];
				[returnString retain];
				currentItunes = returnString;
				return currentItunes;
			}
        }
    } else {
        NSLog(@"Script execution has gone a bit PeteTong: %@", [errorDict objectForKey: @"NSAppleScriptErrorMessage"]);
    }
	return @"None";
}


@end
